; ORIGINAL: 3dt2.1/examples/math.scm
; $Id: math.scm,v 1.3 1996/10/21 15:59:16 aed Exp $
;- math.scm -----------------------------------------------------------
; Define basic math values and procedures.
;----------------------------------------------------------------------

(provide 'math)

(define PI 3.14159265358979323846)
(define PI/2 1.57079632679489661923)
(define (degrees->radians a) (* a 0.0174532925199433))
(define (radians->degrees a) (* a 57.2957795130823))

;; Raise a number to an integer power
(define (expt x n)
  (if (integer? n)
      (let power ((num x)
                  (pow n)
                  (answer 1)
                  )
        (cond
         ((< pow 0) (/ 1 (power num (abs pow) answer)))
         ((= pow 0) answer)
         ((= pow 1) (* answer num))
         ((even? pow) (power (* num num) (/ pow 2) answer))
         (else (power num (- pow 1) (* answer num)))
         ))
      (exp (* n (log x)))
      ))

